import store from '@/store'
import { debug } from '@/env'

export default {
  install: Vue => Vue.directive('auth', {
    bind (el, binding) {
      Vue.nextTick(() => {
        if (debug || store.getters['isSuper']) {
          return
        }
        const authName = binding.arg
        const authorities = store.getters.permissions
        if (authorities.indexOf(authName) === -1) {
          (el.parentNode && el.parentNode.removeChild(el)) || (el.style.display = 'none')
        }
      })
    }
  })
}
